package com.cloudservice.ccs.biz.impl;

import com.cloudservice.ccs.biz.IBlackListBiz;
import com.cloudservice.ccs.entity.BlackList;
import com.cloudservice.ccs.exception.BlackListException;
import com.cloudservice.ccs.exception.CustomerServiceException;
import com.cloudservice.ccs.mapper.BlackListMapper;
import com.cloudservice.ccs.model.BlackListDetail;
import com.cloudservice.ccs.model.BlackListWithCustomerServiceNickName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BlackListImpl implements IBlackListBiz {
    @Autowired
    private BlackListMapper blackListMapper;
    @Override
    public void save(BlackList blackList) {
        int result = blackListMapper.save(blackList);
        if (result == 0) {
            throw new BlackListException("Create BlackList entity error");
        }
    }

    @Override
    public void update(Integer id, BlackList blackList) {
        int result = blackListMapper.update(id, blackList);
        if (result == 0) {
            throw new BlackListException("Update BlackList entity error");
        }
    }

    @Override
    public void partialUpdate(Integer id, Map<String, Object> fields) {
        int result = blackListMapper.partialUpdate(id, fields);
        if (result == 0) {
            throw new BlackListException("Update BlackList entity error");
        }
    }
    @Override
    public void delete(Integer id) {
        int result = blackListMapper.delete(id);
        if (result == 0) {
            throw new BlackListException("Delete BlackList entity error");
        }
    }

    @Override
    public BlackList getOne(Integer id) {
        BlackList blackList = blackListMapper.getOne(id);
        if (blackList == null) {
            throw new BlackListException("Get BlackList entity error: no such entity");
        }
        return blackList;
    }

    @Override
    public List<BlackList> getAll() {
        return blackListMapper.getAll();
    }

    @Override
    public List<BlackListDetail> getAllWithCustomerInfo(Map<String, Object> conditions) {
        return blackListMapper.getAllWithCustomerInfo(conditions);
    }

    @Override
    public List<BlackListWithCustomerServiceNickName> getByCustomerId(Integer customerId) {
        return blackListMapper.getByCustomerId(customerId);
    }
}
